export function debounce<T extends (...args: any) => void>(
  fn: T,
  delay = 50,
): T {
  let timer: number | undefined;
  return function (this: unknown, ...args) {
    if (timer) {
      clearTimeout(timer);
    }
    timer = setTimeout(() => {
      fn.apply(this, args);
      timer = undefined;
    }, delay);
  } as T;
}
